home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 30 / Mac Magazin and MacEasy Magazine CD - Issue 30.iso / utilities / Mac OS X / Load_Monitor / src / TranslucentView.m < prev    next >
Encoding:
Text File  |  2001-11-24  |  2.8 KB  |  104 lines

  1. //
  2. //  TranslucentView.m
  3. //
  4. //  Created by Takashi T. Hamada on Thu Nov 01 2000.
  5. //  Copyright (c) 2000,2001 Takashi T. Hamada. All rights reserved.
  6. //
  7.  
  8. #import "TranslucentView.h"
  9.  
  10.  
  11. @implementation TranslucentView
  12.  
  13. //-------------------------------------------------------------
  14. //    initialization
  15. //-------------------------------------------------------------
  16. - (id)initWithFrame:(NSRect)frameRect
  17. {
  18.     self = [super initWithFrame:frameRect];
  19.  
  20.     calBGViewRectTag = [self addTrackingRect:[self frame] owner:self userData:&ImageOpacity assumeInside:YES];
  21.     theContentDrawer = nil;
  22.  
  23.     return self;
  24. }
  25.  
  26.  
  27. //-------------------------------------------------------------
  28. //    draw translucent rectangle
  29. //-------------------------------------------------------------
  30. - (void)drawRect:(NSRect)rect
  31. {
  32.     [[NSColor clearColor] set];
  33.     NSRectFill( rect );
  34.  
  35.     // draw the content
  36.     if (theContentDrawer != nil)
  37.     [theContentDrawer performSelector:theDrawingMethod];
  38. }
  39.  
  40.  
  41. //-------------------------------------------------------------
  42. //    is this necessary?
  43. //-------------------------------------------------------------
  44. - (BOOL)isOpaque    { return YES; }
  45.  
  46.  
  47. //-------------------------------------------------------------
  48. //    move the window
  49. //-------------------------------------------------------------
  50. - (void)mouseDown:(NSEvent *)theEvent
  51. {
  52.     BOOL         keepOn = YES;
  53.     NSPoint         mouseLoc;
  54.     NSPoint        globalMouseLoc;
  55.     NSPoint        offsetMouseLoc;
  56.     NSPoint        tempWindowLoc;
  57.     NSRect        origFrame;
  58.  
  59.     origFrame = [[self window] frame];
  60.     while( 1 ) {    // gee! entering into the infinity loop...
  61.     mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
  62.  
  63.     switch ([theEvent type]) {
  64.         case NSLeftMouseDown:
  65.         // save the initial mouse location
  66.         offsetMouseLoc = mouseLoc;                
  67.         break;
  68.         case NSLeftMouseDragged:
  69.         // get the mouse location in the global coordinates
  70.         globalMouseLoc = [[self window] convertBaseToScreen:mouseLoc];
  71.         // calculate the new origin of the window
  72.         tempWindowLoc.x = (globalMouseLoc.x - offsetMouseLoc.x);
  73.         tempWindowLoc.y = (globalMouseLoc.y - offsetMouseLoc.y);
  74.         // get the window's location and size in the global coodinate system
  75.         [[self window] setFrameOrigin:tempWindowLoc];    // move and resize the window
  76.         break;
  77.         case NSLeftMouseUp:
  78.         keepOn = NO;
  79.         break;
  80.         default:
  81.         break;
  82.         }
  83.     if (keepOn == NO)
  84.         break;
  85.  
  86.     theEvent = [[self window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask) ];
  87.      };
  88.  
  89.     return;
  90. }
  91.  
  92.  
  93. //-------------------------------------------------------------
  94. //    set the transparency of this view
  95. //-------------------------------------------------------------
  96. - (void)setContentDrawer:(id)theDrawer method:(SEL)theMethod
  97. {
  98.     theContentDrawer = theDrawer;
  99.     theDrawingMethod = theMethod;
  100. }
  101.  
  102.  
  103. @end
  104.